<template>
  <Tab @goBack="goBack" :tabs="tabs" :current="current">
    <div slot="index">
      <el-form :inline="true" label-width="80px">
        <el-form-item label="查询">
          <el-input
            v-model="queryParams.mobile"
            placeholder="用户昵称/手机号码"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="客户端">
          <el-select @keyup.enter.native="handleQuery" v-model="queryParams.role" placeholder="不限"
                     clearable
                     size="small">
            <el-option
              v-for="dict in roleOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        </el-form-item>


      </el-form>

      <el-table v-loading="loading" :data="postList">
        <el-table-column label="用户编号" align="center" prop="idNo" :show-tooltip-when-overflow="true"></el-table-column>
        <el-table-column label="用户昵称" align="center" prop="nickname">
          <template slot-scope="scope">
            <el-link title="查看详情" type="primary"
                     @click="handleUserInfo(scope.row)">{{scope.row.nickname}}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column label="手机号码" align="center" prop="mobile"/>
        <el-table-column label="客户端" align="center" prop="role" :formatter="typeFormat"/>
        <el-table-column label="剩余意豆" align="center" prop="balance">
          <template slot-scope="scope">
            <span>{{scope.row.balance/100||0}}</span>
          </template>
        </el-table-column>
        <el-table-column label="获取意豆" align="center" prop="obtain">
          <template slot-scope="scope">
            <span>{{scope.row.obtain/100||0}}</span>
          </template>
        </el-table-column>
        <el-table-column label="使用意豆" align="center" prop="used">
          <template slot-scope="scope">
            <span>{{scope.row.used/100||0}}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" align="center" width="230">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleObtain(scope.row)"
            >获取记录
            </el-button>
            <el-button
              size="mini"
              type="text"
            >使用记录
            </el-button>
            <!-- @click="handleRecord(scope.row)"-->
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <UserInfo :show="userInfoShow" @close="handleUserInfoClose" v-if="userItem" :item="userItem"></UserInfo>
    </div>
    <div slot="obtain">
      <Obtain :row="row" :role-options="roleOptions"></Obtain>
    </div>
  </Tab>

</template>

<script>
  import Tab from "@/components/Tab";
  import {coinList} from "@/api/coin/list";
  import Obtain from "./obtain";
  import UserInfo from '@/views/components/user';
  import mixin from '@/views/components/user/mixin';

  export default {
    mixins: [mixin],
    components: {Tab, Obtain, UserInfo},
    data() {
      return {
        row: undefined,
        open: false,
        addLoading: false,
        loading: false,
        daterange: undefined,
        areaList: undefined,
        cityList: [],
        postList: [],
        roleOptions: [],
        current: 'index',
        tabs: [
          {index: 'index', name: ''}, {'index': 'obtain', name: '获取列表'},
        ],
        title: '',
        total: 0,
        loadingInstance: undefined,
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          mobile: undefined,
          role: undefined
        }
      }
    },
    created() {
      this.getDicts("yy_user_role").then(response => {
        console.log(response);
        this.roleOptions = response.data;
      });
      this.getList();
    },
    methods: {
      getList() {
        this.loading = true;
        coinList(this.queryDateRange(this.queryParams, this.daterange)).then(response => {
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },

      typeFormat(row, column) {
        let option;
        if (column.property === 'role') {
          option = this.roleOptions;
        }
        return this.selectDictLabel(option, row[column.property]);
      },
      goBack(message) {
        this.current = 'index';
        this.getList();
      },
      handleObtain(row) {
        this.row = row;
        this.current = 'obtain';
      }
    }
  }
</script>

<style>

</style>
